<template >
  <br>
  <van-cell center title="签到提示">
    <template #right-icon>
      <van-switch v-model="checkedSignIn" @click="checkedSignInClick()"/>
    </template>
  </van-cell>
  <br>
  <van-cell center title="签退提示">
    <template #right-icon>
      <van-switch v-model="checkedSignOut" @click="checkedSignOutClick()"/>
    </template>
  </van-cell>
</template>

<script setup>
import {onMounted, reactive, ref} from 'vue';
import {useRouter} from "vue-router";
import myAxios from "../../plugins/myAxios.ts";
import {showToast} from "vant";
import {getCurrentUser} from "../services/user.ts";

const router = useRouter();
const checkedSignIn = ref('');
const checkedSignOut = ref('');
const user = ref('');
onMounted(async () => {
    user.value = await getCurrentUser();
    checkedSignIn.value = user.value.data.signInAlarm === 1 ? true:false;
    checkedSignOut.value = user.value.data.signOutAlarm === 1 ? true:false;
    console.log(user.value);
})

const checkedSignInClick = async () =>{
    user.value.signInAlarm = checkedSignIn.value;
    await myAxios.post('/user/update',{
        id: user.value.data.id,
        signInAlarm: checkedSignIn.value === true ? 1:0,
    })
    showToast("签到提示修改成功")
}
const checkedSignOutClick = async () =>{
    user.value.signInAlarm = checkedSignIn.value;
    await myAxios.post('/user/update',{
        id: user.value.data.id,
        signOutAlarm: checkedSignOut.value === true ? 1:0,
    })
    showToast("签退提示成功")
}
</script>

<style scoped>

</style>